package com.zego.wawaji.ui.center.credit;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.zego.wawaji.R;
import com.zego.wawaji.base.module.ModuleMgr;
import com.noble.library.basic.string.StringUtils;
import com.zego.wawaji.third.image.ImageLoader;
import com.zego.wawaji.ui.base.ExBaseAdapter;
import com.zego.wawaji.ui.bean.wawa.Wawa;
import com.zego.wawaji.ui.center.credit.bean.Credit;

import java.util.List;

/**
 * 兑换积分记录
 * Created by Su on 2017/11/27.
 */
public class CreditAdapter extends ExBaseAdapter<Credit> {
    public CreditAdapter(Context context, List<Credit> datas) {
        super(context, datas);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        MyViewHolder holder;
        if (convertView == null) {
            convertView = inflate(R.layout.my_credit_item);
            holder = new MyViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (MyViewHolder) convertView.getTag();
        }
        final Credit info = getItem(position);

        if (info.getWwTypeId() != 0) {
            Wawa wawa = ModuleMgr.getWawaMgr().getWawa(info.getWwTypeId());
            ImageLoader.loadRoundAvatar(getContext(), wawa.getImg(), holder.type_icon);
        } else {
            ImageLoader.loadRoundAvatar(getContext(), R.drawable.my_credit_type, holder.type_icon);
        }

        holder.type_descl.setText(info.getRemark());
        holder.time_info.setText(StringUtils.getCreateTime(info.getCreateTime()));
        holder.credit_type.setText(info.getTypeStr());
        int wwPoint = info.getWwPoint();
        String strWwPoint = String.valueOf(wwPoint);
        if (wwPoint > 0) {
            strWwPoint = "+" + wwPoint;
        }
        holder.credit_num.setText(strWwPoint);

        return convertView;
    }

    private class MyViewHolder {
        private ImageView type_icon;
        private TextView type_descl, time_info, credit_type, credit_num;

        public MyViewHolder(View convertView) {
            initView(convertView);
        }

        private void initView(View convertView) {
            type_icon = (ImageView) convertView.findViewById(R.id.type_icon);
            type_descl = (TextView) convertView.findViewById(R.id.type_descl);
            time_info = (TextView) convertView.findViewById(R.id.time_info);
            credit_type = (TextView) convertView.findViewById(R.id.credit_type);
            credit_num = (TextView) convertView.findViewById(R.id.credit_num);
        }
    }
}